<?php
    $fout = fopen("map.json", "w");
    $map = array();
    for ($z=0; $z<31; ++$z){
        for ($x=0; $x<31; ++$x){
            for ($y=0; $y<31; ++$y){
                $cell = &$map[$z][$x][$y];
                $cell = array(0,0);
                $z *= 2;
                if ($x - $z >= 0 && $x + $z <= 30
                    && $y - $z >=0 && $y + $z <= 30){
                    $cell[0] = 3;
                }
                $z /= 2;
            }
        }
    }
    for ($z=0; $z<31; ++$z){
        for ($x=0; $x<31; ++$x){
            for ($y=0; $y<31; ++$y){
                $cell = &$map[$z][$x][$y][0];
                if ($cell==3 && $map[$z+1][$x][$y][0] == 3){
                    $cell=0;
                };
            }
        }
    }
    $map[1][0][0][0] = 1;
    $map[1][30][30][0] = 1;
    $map[1][30][0] = array(8, 0);
    $map[2][28][2] = array(8, 1);
    $map[3][26][4] = array(8, 2);
    $map[4][24][6] = array(8, 3);
    
    $map[1][0][30] = array(7, 0);
    $map[2][2][28] = array(7, 1);
    $map[3][4][26] = array(7, 2);
    $map[4][6][24] = array(7, 3);


    $map[1][0][1] = array(6, 0);
    $map[2][2][3] = array(6, 1);
    $map[3][4][5] = array(6, 2);
    $map[4][6][7] = array(6, 3);
    $map[8][16][16] = array(4, 0);
    $map[8][15][15] = array(2, 0);


    //print_r($map);
    print_r(json_encode($map));
    fwrite($fout, json_encode($map));
    fclose($fout);
?>
